//
//  WXLPodsLibResource.m
//  PodsLibDemo
//
//  Created by wxiang on 2020/9/22.
//  Copyright © 2020 wangxiang. All rights reserved.
//

#import "WXLPodsLibResource.h"

@implementation WXLPodsLibResource
/**
 获取库中图片
 */
+ (UIImage *)imageNamed:(NSString *)name {
    
    NSBundle *mainBundle = [self SDKBundle];
    NSLog(@"WXLPodsLibResource bundle = %@",mainBundle);
    
    NSBundle *resourcesBundle = [NSBundle bundleWithPath:[mainBundle pathForResource:@"PodsLibDemo" ofType:@"bundle"]];
    
    if (resourcesBundle == nil) {
        resourcesBundle = mainBundle;
    }

    UIImage *image = [UIImage imageNamed:name inBundle:resourcesBundle compatibleWithTraitCollection:nil];
    
    NSLog(@"resourcesBundle = %@, image = %@", resourcesBundle, image);
    
    return image;
}

/**
 获取库中数据路径
 */
+ (nullable NSString *)pathForResource:(nullable NSString *)name ofType:(nullable NSString *)ext {
    return [[self SDKBundle] pathForResource:name ofType:ext];
}

/**
 获取当前库的Bundle
 */
+ (NSBundle *)SDKBundle {
    return [NSBundle bundleForClass:[WXLPodsLibResource class]];
}

/**
获取当前库的资源文件的Bundle
*/
+ (NSBundle *)resourceBundle {
    NSBundle *mainBundle = [self SDKBundle];
    
    NSBundle *resourcesBundle = [NSBundle bundleWithPath:[mainBundle pathForResource:@"PodsLibDemo" ofType:@"bundle"]];
    
    if (resourcesBundle == nil) {
        resourcesBundle = mainBundle;
    }
    
    NSLog(@"resourceBundle bundle = %@",resourcesBundle);
    return resourcesBundle;
}
@end
